package com.funtl.spring.cloud.alibaba.business.controller;

import com.funtl.spring.cloud.alibaba.business.BusinessAdminFeign;
import com.funtl.spring.cloud.alibaba.provider.api.ProviderAdminService;
import com.funtl.spring.cloud.alibaba.provider.domain.TbAdmin;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @ClassName BusinessAdminController
 * @Description TODO
 * @Author Mr.Starry
 * @Date 2019/12/6 10:08
 * @Version 1.0
 */
@RestController
//@RefreshScope
public class BusinessAdminController {

    @Value(value = "${external.username}")
    private String username;

    @Reference(version = "1.0.0")
    private ProviderAdminService adminService;

    @Value(value = "${server.port}")
    private String port;

    @Resource
    private BusinessAdminFeign adminFeign;

    @GetMapping(value = "hi")
    public String sayHi(){
        return "HTTP "+adminFeign.sayHi()+"消费者"+username;
    }

    @GetMapping(value = "hello")
    public TbAdmin sayHello() {
        return adminService.sayHello("RPC 来自消费者" + port + "的访问");
    }

    @RequestMapping("/login")
    public Object login(String username, HttpServletRequest request) throws IOException {
        request.getSession().setAttribute("userLoginInfo", username);
        return "登录成功"+adminService.sayHello("RPC 来自消费者" + port + "的访问");
    }
}
